from machine import Pin

class TRACKING(object):
    """基本描述
    EF05019
    两路巡线模块
    """

    def __init__(self, pin_l, pin_r):
        self.__pinL = Pin(pin_l, Pin.IN, Pin.PULL_UP)
        self.__pinR = Pin(pin_r, Pin.IN, Pin.PULL_UP)

    def get_state(self):
        """基本描述

        返回当前巡线头状态
        读取1表示白色，0表示黑色

        Returns:
            00 均在白色
            10 左黑右白
            01 左白右黑
            11 均在黑色

        """
        l_value = self.__pinL.value()
        r_value = self.__pinR.value()
        # print(l_value, r_value)

        if l_value == 1 and r_value == 1:
            return 00
        elif l_value == 0 and r_value == 1:
            return 10
        elif l_value == 1 and r_value == 0:
            return 1
        elif l_value == 0 and r_value == 0:
            return 11
        else:
            print("Unknown ERROR")


if __name__ == "__main__":
    import time
    trc = TRACKING(4,5)
    while True:
        print(trc.get_state())
        time.sleep(2)
